# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=rtmpdump

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r494.79459a2
pkgrel=1
pkgdesc="A tool to download rtmp streams (mingw-w64)"
arch=('any')
url="http://rtmpdump.mplayerhq.hu/"
license=('GPL2' 'LGPL2.1')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "git")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-openssl")
options=('strip' 'staticlibs')
source=("$_realname::git+git://git.ffmpeg.org/rtmpdump"
    0001-mingw.mingw.patch
    0002-no-fPIC.mingw.patch
    0003-better-w32-threading.all.patch
    0004-gnu_printf.all.patch
    0005-fix-unused-var-warning.all.patch
    0006-deprecated-gnutls-type.all.patch
    0007-cast-appropriately-for-nettle.all.patch
    0008-unused-variable-warning-fix.all.patch
    0009-correct-cast.all.patch
    0010-unused-variable-fix.all.patch
    0011-fix-parallel-install.all.patch)
md5sums=('SKIP'
         '7328df954e79584ec823b6c9fa99ae3b'
         '3db9a091da6004a3d3f6e8a19be41ba1'
         '45263309e623a7986ee64a1af57f26eb'
         '4dc953f1b65cb0b018c9caf901b233bd'
         'f3b5c78ff1dfd3d6c8d73750c37cd69f'
         'b7e84b140c2416ce9d70aa0121f43518'
         '0b3415a3e2230ec52f4d011220861f47'
         '24789e1365e8331e795faa87a3c4fd3b'
         '3e6dca173d7aee3f520e587e3b6ffbe5'
         '1c60c612bc75cf001f9819e735291c2d'
         '79cb1025e9c84f1bcda1e0c039dbf849')

pkgver() {
  cd "$srcdir/$_realname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p1 -i ${srcdir}/0001-mingw.mingw.patch
  patch -p1 -i ${srcdir}/0002-no-fPIC.mingw.patch
  patch -p1 -i ${srcdir}/0003-better-w32-threading.all.patch
  patch -p1 -i ${srcdir}/0004-gnu_printf.all.patch
  patch -p1 -i ${srcdir}/0005-fix-unused-var-warning.all.patch
  patch -p1 -i ${srcdir}/0006-deprecated-gnutls-type.all.patch
  patch -p1 -i ${srcdir}/0007-cast-appropriately-for-nettle.all.patch
  patch -p1 -i ${srcdir}/0008-unused-variable-warning-fix.all.patch
  patch -p1 -i ${srcdir}/0009-correct-cast.all.patch
  patch -p1 -i ${srcdir}/0010-unused-variable-fix.all.patch
  patch -p1 -i ${srcdir}/0011-fix-parallel-install.all.patch
}

build() {
  cp -rf "${srcdir}/$_realname" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  make CC=gcc LD=ld AR=ar SYS=mingw
}

package() {
    cd "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib
  make CC=gcc LD=ld AR=ar SYS=mingw prefix=${MINGW_PREFIX} mandir=${MINGW_PREFIX}/share/man DESTDIR="$pkgdir" install
  
  mv ${pkgdir}${MINGW_PREFIX}/sbin/* ${pkgdir}${MINGW_PREFIX}/bin/
  rm -r ${pkgdir}${MINGW_PREFIX}/sbin
}
